﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.App_Code;
using Manager.Common;

namespace Manager.FormAdd_Edit
{
    public partial class Frm_LoadListCustomer : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();
        public KhachHang khachHang = null;

        public Frm_LoadListCustomer()
        {
            InitializeComponent();
            khachHang = new KhachHang();
        }

        private void Frm_LoadListCustomer_Load(object sender, EventArgs e)
        {
            dateDenNgay.Text = DateTime.Now.ToShortDateString();
            dateTuNgay.Text = DateTime.Now.AddDays(-90).ToShortDateString();
            var lstKhachHang = db.KhachHangs.Where(i => i.NgayTao <= DateTime.Now && i.NgayTao >= DateTime.Now.AddDays(-90)).ToList();
            gridControl1.DataSource = lstKhachHang;
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int index = gridView1.FocusedRowHandle;
                khachHang = gridView1.GetRow(index) as KhachHang;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi xảy ra!!!");
                Log.WriteLog("Frm_LoadListCustomer:gridControl1_DoubleClick " + ex.Message + "\n" + ex.StackTrace);
            }
        }

        private void btnTim_Click(object sender, EventArgs e)
        {            
            try
            {
                var lstKhachHang = db.KhachHangs.Where(i => i.NgayTao <= dateDenNgay.DateTime && i.NgayTao >= dateTuNgay.DateTime).ToList();
                gridControl1.DataSource = lstKhachHang;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi xảy ra!!!");
                Log.WriteLog("Frm_LoadListCustomer:btnTim_Click " + ex.Message + "\n" + ex.StackTrace);
            }

        }      
    }
}